<?php 
/**
 * 用户注册管理控制器
 */
class RegisterController extends Controller{
	private $model;
	public function __init(){
		$this->model = K('User');
	}
	
	public function index(){
		if(IS_POST){
			$data = array(
				'username' => Q('post.username'),
				'password' => Q('post.password','','md5'),
				'nick'     => Q('nick'),
				'restime'  => time()
			);
			if(!$this->model->register($data)) $this->error($this->model->error);
			$this->success('注册成功',U('Index/index'));
		}
		
		$this->display();
	}
	
	/**
	 * 显示验证码
	 */
	public function code(){
		$code = new Code();
		$code->show();
	}
	/**
	 * 用户名是否已存在验证
	 */
	public function ajaxCheckuser(){
		$user = Q('post.user');
		$userIn = $this->model->where("username='{$user}'")->find();
		if($userIn){
			echo 0;die;
		}else{
			echo 1;die;
		}
		
		
	}
	
	/**
	 * 异步检测验证码
	 */
	public function ajaxCheckcode(){
		$code = Q('post.code','','strtoupper');
		if($_SESSION['code']==$code){
			echo 1;die;
		}else{
			echo 0;die;
		}
		
	}	
	
	
	
	
	
	
}












 ?>